<?php
//自动生成,请根据需要修改
namespace app\user\controller;
use app\common\controller\Base;
use think\facade\Request;
use think\Db;
/**
* @title 用户接口
* @description 用户说明
* @group 用户
*/
class User extends Base{

	/**
	* @title 插入记录
	* @description 插入用户数据
	* @author 开发者（刘春明）
	* @url /user/user/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:openid type:VarChar require:1 default:0 other: desc:openID
	* @param name:avatarUrl type:VarChar require:1 default:0 other: desc:头像
	* @param name:nickName type:VarChar require:1 default:0 other: desc:昵称
	* @param name:gender type:TinyInt require:1 default:0 other: desc:性别
	* @param name:country type:VarChar require:1 default:0 other: desc:国家
	* @param name:city type:VarChar require:1 default:0 other: desc:城市
	* @param name:province type:VarChar require:1 default:0 other: desc:省份
	* @param name:language type:VarChar require:1 default:0 other: desc:语言
	* @param name:merchantID type:Int require:1 default:0 other: desc:商家ID
	* @param name:createTime type:Int require:1 default:0 other: desc:创建时间
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态
	* @param name:phone type:VarChar require:1 default:0 other: desc:电话
	*
	*
	* @return openid:openID
	* @return avatarUrl:头像
	* @return nickName:昵称
	* @return gender:性别
	* @return country:国家
	* @return city:城市
	* @return province:省份
	* @return language:语言
	* @return merchantID:商家ID
	* @return createTime:创建时间
	* @return status:状态
	* @return phone:电话
	*
	*/
	public function add (){
		//模块 - 输入数据
		$input['openid'] = Request::post('openid');
		$input['avatarUrl'] = Request::post('avatarUrl');
		$input['nickName'] = Request::post('nickName');
		$input['gender'] = Request::post('gender');
		$input['country'] = Request::post('country');
		$input['city'] = Request::post('city');
		$input['province'] = Request::post('province');
		$input['language'] = Request::post('language');
		$input['merchantID'] = Request::post('merchantID/s');
		$input['createTime'] = Request::post('createTime/s');
		$input['status'] = Request::post('status');
		$input['phone'] = Request::post('phone');


		//模块 - 验证器
		$userValidate = new \app\user\validate\User;
		$validate = $userValidate->scene('except_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $userValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'openid'=>$input['openid'],
			'avatarUrl'=>$input['avatarUrl'],
			'nickName'=>$input['nickName'],
			'gender'=>$input['gender'],
			'country'=>$input['country'],
			'city'=>$input['city'],
			'province'=>$input['province'],
			'language'=>$input['language'],
			'merchantID'=>$input['merchantID'],
			'createTime'=>$input['createTime'],
			'status'=>$input['status'],
			'phone'=>$input['phone'],
		];
		//添加数据
		$insert_res = Db::name('user')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取用户的列表数据（分页）
	* @author 开发者（刘春明）
	* @url /user/user/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:openid type:VarChar require:1 default:0 other: desc:openID
	* @param name:avatarUrl type:VarChar require:1 default:0 other: desc:头像
	* @param name:nickName type:VarChar require:1 default:0 other: desc:昵称
	* @param name:gender type:TinyInt require:1 default:0 other: desc:性别
	* @param name:country type:VarChar require:1 default:0 other: desc:国家
	* @param name:city type:VarChar require:1 default:0 other: desc:城市
	* @param name:province type:VarChar require:1 default:0 other: desc:省份
	* @param name:language type:VarChar require:1 default:0 other: desc:语言
	* @param name:merchantID type:Int require:1 default:0 other: desc:商家ID
	* @param name:createTime type:Int require:1 default:0 other: desc:创建时间
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态
	* @param name:phone type:VarChar require:1 default:0 other: desc:电话
	*
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return id:id
	* @return openid:openID
	* @return avatarUrl:头像
	* @return nickName:昵称
	* @return gender:性别
	* @return country:国家
	* @return city:城市
	* @return province:省份
	* @return language:语言
	* @return merchantID:商家ID
	* @return createTime:创建时间
	* @return status:状态
	* @return phone:电话
	*
	*/
	public function get_list (){
		//模块 - 输入数据
		$input['id'] = Request::param('id/s');
		$input['openid'] = Request::param('openid');
		$input['avatarUrl'] = Request::param('avatarUrl');
		$input['nickName'] = Request::param('nickName');
		$input['gender'] = Request::param('gender');
		$input['country'] = Request::param('country');
		$input['city'] = Request::param('city');
		$input['province'] = Request::param('province');
		$input['language'] = Request::param('language');
		$input['merchantID'] = Request::param('merchantID/s');
		$input['createTime'] = Request::param('createTime/s');
		$input['status'] = Request::param('status');
		$input['phone'] = Request::param('phone');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['openid'] = $input['openid'];
		$msg['data']['avatarUrl'] = $input['avatarUrl'];
		$msg['data']['nickName'] = $input['nickName'];
		$msg['data']['gender'] = $input['gender'];
		$msg['data']['country'] = $input['country'];
		$msg['data']['city'] = $input['city'];
		$msg['data']['province'] = $input['province'];
		$msg['data']['language'] = $input['language'];
		$msg['data']['merchantID'] = $input['merchantID'];
		$msg['data']['createTime'] = $input['createTime'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['phone'] = $input['phone'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['openid','like','%'.$input['openid'].'%'],
			['avatarUrl','like','%'.$input['avatarUrl'].'%'],
			['nickName','like','%'.$input['nickName'].'%'],
			['gender','=',$input['gender']],
			['country','like','%'.$input['country'].'%'],
			['city','like','%'.$input['city'].'%'],
			['province','like','%'.$input['province'].'%'],
			['language','like','%'.$input['language'].'%'],
			['merchantID','=',$input['merchantID']],
			['createTime','=',$input['createTime']],
			['status','=',$input['status']],
			['phone','like','%'.$input['phone'].'%'],
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('user')->where($paginate_map)->paginate();

		// paginate 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（select）
	* @description 获取用户的列表数据（无分页）
	* @author 开发者（刘春明）
	* @url /user/user/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:openid type:VarChar require:1 default:0 other: desc:openID
	* @param name:avatarUrl type:VarChar require:1 default:0 other: desc:头像
	* @param name:nickName type:VarChar require:1 default:0 other: desc:昵称
	* @param name:gender type:TinyInt require:1 default:0 other: desc:性别
	* @param name:country type:VarChar require:1 default:0 other: desc:国家
	* @param name:city type:VarChar require:1 default:0 other: desc:城市
	* @param name:province type:VarChar require:1 default:0 other: desc:省份
	* @param name:language type:VarChar require:1 default:0 other: desc:语言
	* @param name:merchantID type:Int require:1 default:0 other: desc:商家ID
	* @param name:createTime type:Int require:1 default:0 other: desc:创建时间
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态
	* @param name:phone type:VarChar require:1 default:0 other: desc:电话
	*
	*
	* @return id:id
	* @return openid:openID
	* @return avatarUrl:头像
	* @return nickName:昵称
	* @return gender:性别
	* @return country:国家
	* @return city:城市
	* @return province:省份
	* @return language:语言
	* @return merchantID:商家ID
	* @return createTime:创建时间
	* @return status:状态
	* @return phone:电话
	*
	*/
	public function get_select (){
		//模块 - 输入数据
		$input['id'] = Request::param('id/s');
		$input['openid'] = Request::param('openid');
		$input['avatarUrl'] = Request::param('avatarUrl');
		$input['nickName'] = Request::param('nickName');
		$input['gender'] = Request::param('gender');
		$input['country'] = Request::param('country');
		$input['city'] = Request::param('city');
		$input['province'] = Request::param('province');
		$input['language'] = Request::param('language');
		$input['merchantID'] = Request::param('merchantID/s');
		$input['createTime'] = Request::param('createTime/s');
		$input['status'] = Request::param('status');
		$input['phone'] = Request::param('phone');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['openid'] = $input['openid'];
		$msg['data']['avatarUrl'] = $input['avatarUrl'];
		$msg['data']['nickName'] = $input['nickName'];
		$msg['data']['gender'] = $input['gender'];
		$msg['data']['country'] = $input['country'];
		$msg['data']['city'] = $input['city'];
		$msg['data']['province'] = $input['province'];
		$msg['data']['language'] = $input['language'];
		$msg['data']['merchantID'] = $input['merchantID'];
		$msg['data']['createTime'] = $input['createTime'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['phone'] = $input['phone'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['openid','like','%'.$input['openid'].'%'],
			['avatarUrl','like','%'.$input['avatarUrl'].'%'],
			['nickName','like','%'.$input['nickName'].'%'],
			['gender','=',$input['gender']],
			['country','like','%'.$input['country'].'%'],
			['city','like','%'.$input['city'].'%'],
			['province','like','%'.$input['province'].'%'],
			['language','like','%'.$input['language'].'%'],
			['merchantID','=',$input['merchantID']],
			['createTime','=',$input['createTime']],
			['status','=',$input['status']],
			['phone','like','%'.$input['phone'].'%'],
		];
		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);
		}

		//获取数据
		$select_res = Db::name('user')->where($select_map)->select();

		// select 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取单条数据
	* @description 根据ID获取用户的指定记录
	* @author 开发者（刘春明）
	* @url /user/user/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function info (){
		//模块 - 输入数据
		$input['id'] = Request::param('id/s');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$userValidate = new \app\user\validate\User;
		$validate = $userValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $userValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('user')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新用户指定记录的数据
	* @author 开发者（刘春明）
	* @url /user/user/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:openid type:VarChar require:1 default:0 other: desc:openID
	* @param name:avatarUrl type:VarChar require:1 default:0 other: desc:头像
	* @param name:nickName type:VarChar require:1 default:0 other: desc:昵称
	* @param name:gender type:TinyInt require:1 default:0 other: desc:性别
	* @param name:country type:VarChar require:1 default:0 other: desc:国家
	* @param name:city type:VarChar require:1 default:0 other: desc:城市
	* @param name:province type:VarChar require:1 default:0 other: desc:省份
	* @param name:language type:VarChar require:1 default:0 other: desc:语言
	* @param name:merchantID type:Int require:1 default:0 other: desc:商家ID
	* @param name:createTime type:Int require:1 default:0 other: desc:创建时间
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态
	* @param name:phone type:VarChar require:1 default:0 other: desc:电话
	*
	*
	* @return id:id
	* @return openid:openID
	* @return avatarUrl:头像
	* @return nickName:昵称
	* @return gender:性别
	* @return country:国家
	* @return city:城市
	* @return province:省份
	* @return language:语言
	* @return merchantID:商家ID
	* @return createTime:创建时间
	* @return status:状态
	* @return phone:电话
	*
	*/
	public function edit (){
		//模块 - 输入数据
		$input['id'] = Request::post('id/s');
		$input['openid'] = Request::post('openid');
		$input['avatarUrl'] = Request::post('avatarUrl');
		$input['nickName'] = Request::post('nickName');
		$input['gender'] = Request::post('gender');
		$input['country'] = Request::post('country');
		$input['city'] = Request::post('city');
		$input['province'] = Request::post('province');
		$input['language'] = Request::post('language');
		$input['merchantID'] = Request::post('merchantID/s');
		$input['createTime'] = Request::post('createTime/s');
		$input['status'] = Request::post('status');
		$input['phone'] = Request::post('phone');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['openid'] = $input['openid'];
		$msg['data']['avatarUrl'] = $input['avatarUrl'];
		$msg['data']['nickName'] = $input['nickName'];
		$msg['data']['gender'] = $input['gender'];
		$msg['data']['country'] = $input['country'];
		$msg['data']['city'] = $input['city'];
		$msg['data']['province'] = $input['province'];
		$msg['data']['language'] = $input['language'];
		$msg['data']['merchantID'] = $input['merchantID'];
		$msg['data']['createTime'] = $input['createTime'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['phone'] = $input['phone'];

		//模块 - 验证器
		$userValidate = new \app\user\validate\User;
		$validate = $userValidate->scene('all_field')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $userValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'id'=>$input['id'],
			'openid'=>$input['openid'],
			'avatarUrl'=>$input['avatarUrl'],
			'nickName'=>$input['nickName'],
			'gender'=>$input['gender'],
			'country'=>$input['country'],
			'city'=>$input['city'],
			'province'=>$input['province'],
			'language'=>$input['language'],
			'merchantID'=>$input['merchantID'],
			'createTime'=>$input['createTime'],
			'status'=>$input['status'],
			'phone'=>$input['phone'],
		];
		//获取数据
		$update_res = Db::name('user')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 按条件删除记录
	* @description 按条件删除用户的数据
	* @author 开发者（刘春明）
	* @url /user/user/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:openid type:VarChar require:1 default:0 other: desc:openID
	* @param name:avatarUrl type:VarChar require:1 default:0 other: desc:头像
	* @param name:nickName type:VarChar require:1 default:0 other: desc:昵称
	* @param name:gender type:TinyInt require:1 default:0 other: desc:性别
	* @param name:country type:VarChar require:1 default:0 other: desc:国家
	* @param name:city type:VarChar require:1 default:0 other: desc:城市
	* @param name:province type:VarChar require:1 default:0 other: desc:省份
	* @param name:language type:VarChar require:1 default:0 other: desc:语言
	* @param name:merchantID type:Int require:1 default:0 other: desc:商家ID
	* @param name:createTime type:Int require:1 default:0 other: desc:创建时间
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态
	* @param name:phone type:VarChar require:1 default:0 other: desc:电话
	*
	*
	* @return id:id
	* @return openid:openID
	* @return avatarUrl:头像
	* @return nickName:昵称
	* @return gender:性别
	* @return country:国家
	* @return city:城市
	* @return province:省份
	* @return language:语言
	* @return merchantID:商家ID
	* @return createTime:创建时间
	* @return status:状态
	* @return phone:电话
	*
	*/
	public function delete (){
		//模块 - 输入数据
		$input['id'] = Request::post('id/s');
		$input['openid'] = Request::post('openid');
		$input['avatarUrl'] = Request::post('avatarUrl');
		$input['nickName'] = Request::post('nickName');
		$input['gender'] = Request::post('gender');
		$input['country'] = Request::post('country');
		$input['city'] = Request::post('city');
		$input['province'] = Request::post('province');
		$input['language'] = Request::post('language');
		$input['merchantID'] = Request::post('merchantID/s');
		$input['createTime'] = Request::post('createTime/s');
		$input['status'] = Request::post('status');
		$input['phone'] = Request::post('phone');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['openid'] = $input['openid'];
		$msg['data']['avatarUrl'] = $input['avatarUrl'];
		$msg['data']['nickName'] = $input['nickName'];
		$msg['data']['gender'] = $input['gender'];
		$msg['data']['country'] = $input['country'];
		$msg['data']['city'] = $input['city'];
		$msg['data']['province'] = $input['province'];
		$msg['data']['language'] = $input['language'];
		$msg['data']['merchantID'] = $input['merchantID'];
		$msg['data']['createTime'] = $input['createTime'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['phone'] = $input['phone'];

		// ---  模块 - 删除  ---
		//删除的条件
		$temp_map = [
			['id','=',$input['id']],
			['openid','=',$input['openid']],
			['avatar_url','=',$input['avatarUrl']],
			['nick_name','=',$input['nickName']],
			['gender','=',$input['gender']],
			['country','=',$input['country']],
			['city','=',$input['city']],
			['province','=',$input['province']],
			['language','=',$input['language']],
			['merchant_i_d','=',$input['merchantID']],
			['create_time','=',$input['createTime']],
			['status','=',$input['status']],
			['phone','=',$input['phone']],
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]==0 || !empty($v[2])){
				array_push($delete_map,$v);
			}
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('user')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 用户个人信息
	* @description 用户个人信息
	* @author 开发者（刘春明）
	* @url /user/user/user_info
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function user_info (){
		//模块 - 输入数据
		$input['id'] = Request::post('id/s');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_re = Db::name('user')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_re;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
    /**
     * @title 用户订单列表
     * @description 用户订单列表
     * @author 开发者（刘春明）
     * @url /user/user/user_order
     * @method post
     *
     * @param name:token require:1 default: desc:token
     * @param name:orderStatus require:1 default: desc:订单状态(obligation-待支付；shipments-待发货；receiving-待收货；afterSale-售后；returnSuccess-退货成功；refundSuccess-退款成功；success-交易完成；cancel-交易关闭；)
     * @param name:page require:1 default: desc:页数
     * @param name:pagesize require:1 default: desc:每页数量
     * @return id:id
     *
     */
    public function user_order()
    {

        $user=Db::name('user')
            ->where('id',ACCOUNTID)
            ->withAttr('order',function($value,$data){
                $msg = input();
                if(isset($msg['orderStatus'])){
                    $order=get_curl('order','order/select_order',['token'=>$msg['token'],'userID'=>$data['id'],'orderStatus'=>$msg['orderStatus'],'page'=>$msg['page'],'pagesize'=>$msg['pagesize']]);
                }else{
                    $order=get_curl('order','order/select_order',['token'=>$msg['token'],'userID'=>$data['id'],'page'=>$msg['page'],'pagesize'=>$msg['pagesize']]);
                }
                if ($order['status']==true){
                    $order=$order['list'];
                }else{
                    $order=[];
                }
                return $order;
            })
            ->field(['id','nickName'])
            ->find();

        if(!$user){
            $msg['msg'] = '该用户不存在';
            $msg['error_code'] = 'not_user';
            return $this->errorJson($msg);
        }
        $msg['msg'] = '操作成功！';
        $msg['data'] = $user;
        return $this->successJson($msg);
    }

    /**
     * @title 用户收货地址(默认地址存在的话 查询默认地址，不存在的话查询全部地址)
     * @description 用户收货地址
     * @author 开发者（刘春明）
     * @url /user/user/user_address
     * @method post
     *
     * @param name:token require:1 default: desc:token
     * @param name:isDefault type:Int require:1 default:0 other: desc:是否查询默认地址
     *
     *
     * @return id:id
     *
     */
    public function user_address()
    {
        $user=Db::name('user')
            ->where('id',ACCOUNTID)
            ->withAttr('address',function($value,$data){
                $msg=input();
                if (isset($msg['isDefault']) && !empty($msg['isDefault']) && $msg['isDefault']!=null && $msg['isDefault']!=''){
                    $address=Db::name('address')
                        ->where(['userID'=>$data['id'],'isDefault'=>1,'isDelete'=>0])
                        ->select();
                }else{
                    $address=Db::name('address')
                        ->where(['userID'=>$data['id'],'isDelete'=>0])
                        ->select();
                }
                return $address;
            })
            ->field(['id','nickName'])
            ->find();
        $msg['msg'] = '操作成功！';
        $msg['data'] = $user;
        return $this->successJson($msg);
    }

    /**
     * @title 后台查询订单用户信息
     * @description 后台查询订单用户信息
     * @author 刘春明
     * @url /user/user/order_user
     * @param name:user_id require:1 default: desc:用户id
     */
    public function order_user()
    {
        $data=input();
        $user=Db::name('user')
            ->where('id',$data['user_id'])
            ->select();
        $msg['data'] = $user;
        return $this->successJson($msg);
    }

    /**
     * @title 前台添加用户
     * @description 前台添加用户
     * @author 李锐志
     * @url /user/user/add_user
     * @method *
     * @param name:account_id require:1 default: desc:account_id
     * @param name:nickName require:1 default: desc:昵称
     * @param name:gender require:1 default: desc:性别
     * @param name:country require:1 default: desc:国家
     * @param name:city require:1 default: desc:城市
     * @param name:province require:1 default: desc:省份
     * @param name:language require:1 default: desc:语言
     * @param name:avatarUrl require:1 default: desc:头像
     */
    public function add_user()
    {
        $wx_user = input();
        $user_id = Db::name('user')
            ->strict(false)
            ->insertGetId([
                'account_id'=>$wx_user['account_id'],
                'nickName'=>$wx_user['nickName'],
                'gender'=>$wx_user['gender'],
                'country'=>$wx_user['country'],
                'province'=>$wx_user['province'],
                'city'=>$wx_user['city'],
                'avatarUrl'=>$wx_user['avatarUrl'],
                'language'=>$wx_user['language']
            ]);
        $data = Db::name('user')
            ->where('id',$user_id)
            ->field('openid,id')
            ->find();

        $msg['msg'] = '添加成功';
        $msg['data'] = $data;
        return $this->successJson($msg);
    }
    /**
     * @title 前台token查询用户信息
     * @description 前台token查询用户信息
     * @author 刘荣狄
     * @url /user/user/get_usr_message
     * @param name:token require:1 default: desc:token
     */
    public function get_usr_message()
    {
        $data=input();
        $user=Db::name('user')
            ->where('id',ACCOUNTID)
            ->find();
        $msg['data'] = $user;
        return $this->successJson($msg);
    }
}
